package com.linkage.educloud.ah.mvp.presenter.mine;

import android.content.Context;

import com.linkage.educloud.ah.bean.VClassBean;
import com.linkage.educloud.ah.http.Method;
import com.linkage.educloud.ah.http.RequestUtil;
import com.linkage.educloud.ah.mvp.contract.mine.IMyBagContract;
import com.linkage.educloud.ah.mvp.contract.mine.IVClassContract;
import com.linkage.educloud.ah.mvp.model.mine.MyBagModel;
import com.linkage.educloud.ah.mvp.model.mine.VClassModel;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.subsciber.BaseSubscriber;
import com.zzhou.common.library.util.ToastShow;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;

/**
 * Created by Mr'Tang on 2018/12/12.
 */

public class MyBagPresenter extends IMyBagContract.IPresenter<IMyBagContract.IView> {
    Context mContext;
    IMyBagContract.IModel iModel;

    public MyBagPresenter(Context context, IMyBagContract.IView iView) {
        super(iView);
        mContext = context;
        iModel = new MyBagModel();
    }

//    //发表反馈意见
//    @Override
//    public void getVClassSurplus(int usertype, String tel) {
//        Observable observable = iModel.request(Method.POST, true, RequestUtil.getVClassSurplus(usertype, tel));
//        observable.compose(iView.bindLifecycle())
//                .subscribe(new BaseSubscriber<String>() {
//                    @Override
//                    public void onNext(String s) {
//                        try {
//                            JSONObject json = new JSONObject(s);
//                            if (json.getInt("ret") == 0) {
//                                int total = json.optInt("totaltime");
//                                int used = json.optInt("usedtime");
//                                List<VClassBean> list = new ArrayList<>();
//                                if (json.has("childusedlist")) {
//                                    list = VClassBean.parseFromJson(json.optJSONArray("childusedlist"));
//                                }
//                                ((IVClassContract.IView) iView).initDateSuccess(total, used, list);
//                            } else {
//                                ToastShow.show(mContext, json.getString("msg"));
//                                ((IVClassContract.IView) iView).initDateError();
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                            ToastShow.show(mContext, e.getMessage());
//                        }
//                    }
//
//                    @Override
//                    public void onError(ApiException e) {
//
//                    }
//                });
//    }
}

